How to create an RPM package using Chef, Test Kitchen

This post describes how to leverage Chef and Test Kitchen to create a pristine virtual machine from which to create an RPM package.

Background

I needed customized versions of the FcgiWrap and Postfix RPM packages and preferred to develop a method that would allow me to periodically update the packages as new versions of the upstream source were released. Vagrant is a great tool for managing virtual machines and I was originally going to use this to provision a new VM to build the packages. I developed Chef cookbooks to provision the VMs, and while developing integration tests for the provisioners, I realized that it was more effective to use Test Kitchen to build and test my VMs (which itself uses Vagrant).

Prerequisites

The following are required:

  • Git (v2.2.1 used)
  • Ruby (v2.1.5 used)
  • Chef (v11.16.4 used)
  • Test Kitchen (v1.2.1 used)
  • Vagrant (v1.6.5 used)
  • Virtual machine (Parallels 10.0.0 used, but VirtualBox works as well)

Example / FcgiWrap

Clone the repository and use kitchen to converge the node:

1
2
3
4
5
6
7
$ git clone https://github.com/4-20ma/cookbook-fcgiwrap_rpm
$ cd cookbook-fcgiwrap_rpm
$ bundle exec kitchen converge
...
$ tree .products/
.products/
└── fcgiwrap-1.1.0-1.el6.x86_64.rpm

You can now transfer the .rpm file to the target machine(s) and install via rpm or yum.

Example / Postfix

Clone the repository and use kitchen to converge the node:

1
2
3
4
5
6
7
8
$ git clone https://github.com/4-20ma/cookbook-postfix_rpm
$ cd cookbook-postfix_rpm
$ bundle exec kitchen converge
...
$ tree .products/
.products/
├── postfix-2.11.1-0.el6.x86_64.rpm
└── postfix-perl-scripts-2.11.1-0.el6.x86_64.rpm

You can now transfer the .rpm file to the target machine(s) and install via rpm or yum.

Summary

Test Kitchen is not only effective at performing integration testing for a Chef cookbook, it is also useful to spin up a pristine virtual machine to perform tasks such as building an RPM package.

((( - )))

References

Cookbook Sources:

3rd party software used (alphabetical):